package com.jbookshelf.dal.providers;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.jbookshelf.dal.entities.OrderStatuses;
import com.jbookshelf.dal.enums.OrderState;

@Repository
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public class StatusesDataProviderImpl implements StatusesDataProvider {

	@Autowired
	SessionFactory sessionFactory;

	@Override
	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
	public OrderStatuses getStatus(OrderState state) {
		return (OrderStatuses)sessionFactory.getCurrentSession().get(OrderStatuses.class,state.index());
	}

}
